package com.example.util;

import com.example.common.DefaultWatcher;
import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;
import java.util.concurrent.CountDownLatch;

public class ZKUtil {

    private static ZooKeeper zk;
    private static CountDownLatch cd = new CountDownLatch(1);

    public static ZooKeeper getZKClient() {

        try {
            zk = new ZooKeeper("192.168.1.101:2181,192.168.1.102:2181,192.168.1.103:2181,192.168.1.104:2181/testLock",
                    1000, new DefaultWatcher(cd));

            cd.await();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return zk;
    }

}
